package org.gdpi.service;

import org.gdpi.bean.Manager;
import org.gdpi.bean.Student;
import org.gdpi.bean.Teacher;
import org.gdpi.dao.LoginDao;
import org.gdpi.service.ex.LoginException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class LoginServiceImpl implements LoginService {

    @Resource
    private LoginDao loginDao;

    public Manager loginByManager(String userName, String password) {
        Manager manager = loginDao.loginByManager(userName);
        if (manager == null) {
            throw new LoginException("账户不存在");
        } else {
            if (manager.getMana_pwd().equals(password)) {
                return manager;
            } else {
                throw new LoginException("密码错误！");
            }
        }
    }

    public Student loginByStudent(String userName, String password) {
        Student student = loginDao.loginByStudent(userName);
        if (student == null) {
            throw new LoginException("账户不存在");
        } else {
            if (student.getStu_pwd().equals(password)) {
                return student;
            } else {
                throw new LoginException("密码错误！");
            }
        }
    }

    public Teacher loginByTeacher(String userName,String password){
        Teacher teacher = loginDao.loginByTeacher(userName);
        if (teacher == null) {
            throw new LoginException("账户不存在");
        } else {
            if (teacher.getTea_pwd().equals(password)) {
                return teacher;
            } else {
                throw new LoginException("密码错误！");
            }
        }
    }
}